
#ifndef  WIRELESSPROCESS
#define  WIRELESSPROCESS

#include <ioCC2430.h>
#include <hal_cc8051.h>


#define __bsp_LED_TURN_ON__(bit,port,ddr,low)  \
  st( if (low) { port &= ~BV(bit); } else { port |= BV(bit); } )

#define __bsp_LED_TURN_OFF__(bit,port,ddr,low)  \
  st( if (low) { port |= BV(bit); } else { port &= ~BV(bit); } )

#define __bsp_LED_TOGGLE__(bit,port,ddr,low)     st( port ^= BV(bit); )

#define LED1_TURN_ON()    __bsp_LED_TURN_ON__ ( 0, P1, P1DIR, 1 )
#define LED1_TURN_OFF()   __bsp_LED_TURN_OFF__( 0, P1, P1DIR, 1 )

#define LED2_TURN_ON()    __bsp_LED_TURN_ON__ ( 1, P1, P1DIR, 1 )
#define LED2_TURN_OFF()   __bsp_LED_TURN_OFF__( 1, P1, P1DIR, 1 )

#define LED1_TOGGLE()    __bsp_LED_TOGGLE__( 0, P1, P1DIR, 1 )
#define LED2_TOGGLE()    __bsp_LED_TOGGLE__( 1, P1, P1DIR, 1 )

#define LED_OFF 1
#define LED_ON  0
#define LED1          P1_0
#define LED3          P1_1

#define INIT_LED1()      do { LED1 = LED_OFF; IO_DIR_PORT_PIN(1, 0, IO_OUT); P1SEL &= ~0x01;} while (0)
#define INIT_LED3()      do { LED3 = LED_OFF; IO_DIR_PORT_PIN(1, 1, IO_OUT); P1SEL &= ~0x02;} while (0)

#define      GATEWAY       0x00
//                              PC send     recorder send
#define  HAND_SHAKE                             0x01

#define  THRESHOLD_SET            0x02
#define  THRESHOLD_SET_BACK                     0x12


#define  CLOCK_SET                0x03
#define  CLOCK_SET_BACK                         0x13


#define  COLLECT_TIME_SET         0x04
#define  COLLECT_TIME_SET_BACK                  0x14


#define  THRESHOLD_READ           0x05
#define  THRESHOLD_READ_BACK                    0x15


#define  CLOCK_READ               0x06
#define  CLOCK_READ_BACK                        0x16


#define  TH_DATA_READ             0x07
#define  TH_DATA_READ_BACK                      0x17


#define  A_PAGE_COMPLETE                        0x08
#define  A_PAGE_COMPLETE_BACK     0x18


#define  ALL_PAGE_COMPLETE                      0x09
#define  ALL_PAGE_COMPLETE_BACK   0x19


#define  COLLECT_TIME_READ        0x0A
#define  COLLECT_TIME_READ_BACK                 0x1A

#define  WIRELESS_CLOSE           0x0B


#define TIME_OUT   30                        //30s
#define NODE_ID      0X03

#define ADDRESS_0 0x00

#define ADDRESS_1 0x01
#define ADDRESS_2 0x02
#define ADDRESS_3 0x03
#define ADDRESS_4 0x04


//background
#define  FLASH_PAGE_READ          0x0C
#define  FLASH_PAGE_READ_BACK                   0x1C

#define  RESTORE_FACTORY_SET      0x0D
#define  RESTORE_FACTORY_SET_BACK               0x1D

#define  WHICH_TWO_PAGE           0x0E
#define  WHICH_TWO_PAGE_BACK                    0x1E

extern uint8 TimeOut;

extern uint8 write_flag;
extern uint8 uart_buf[30];
extern uint8 uart_len;

// Prototype for local functions//uart

extern void HalUARTInit( void );
extern void UartTX_Send_String0(uint8 *Data,uint8 len);
void   SPIMgr_ProcessRxData(uint8 ch);
#endif